package br.com.obardavez.web.filter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class CrossDomainFilter implements Filter {
	public void init(FilterConfig config) throws ServletException {

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws java.io.IOException, ServletException {

		((HttpServletResponse) response).addHeader("Access-Control-Allow-Origin", "*");
		((HttpServletResponse) response).addHeader("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
		((HttpServletResponse) response).addHeader("Cache-Control", "no-cache");
		((HttpServletResponse) response).addHeader("Access-Control-Allow-Headers", "origin, x-requested-with, content-type");
		((HttpServletResponse) response).addHeader("Access-Control-Max-AgeAccess-Control-Max-Age", "1728000");
		
		chain.doFilter(request, response);
	}

	public void destroy() {
	}
}